<template>
  <div class="home">
    <!-- 欢迎区域 -->
    <el-card class="welcome-card">
      <template #header>
        <div class="card-header">
          <h3>欢迎使用Vue子应用</h3>
        </div>
      </template>
      <div class="welcome-content">
        <p>这是一个基于Vue 3 + Element Plus构建的子应用，提供以下功能：</p>
        <ul>
          <li>商品管理：商品的增删改查功能</li>
          <li>订单管理：订单的处理和跟踪</li>
          <li>数据统计：销售数据和趋势分析</li>
        </ul>
        <p>点击左侧菜单可以访问不同的功能模块。</p>
      </div>
    </el-card>

    <!-- 数据统计卡片 -->
    <el-row :gutter="20" class="stats-row">
      <el-col :xs="24" :sm="12" :lg="6">
        <el-card class="stats-card">
          <div class="stats-content">
            <div class="stats-icon sales">
              <el-icon><TrendCharts /></el-icon>
            </div>
            <div class="stats-info">
              <div class="stats-value">¥128,430</div>
              <div class="stats-label">今日销售额</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="12" :lg="6">
        <el-card class="stats-card">
          <div class="stats-content">
            <div class="stats-icon orders">
              <el-icon><List /></el-icon>
            </div>
            <div class="stats-info">
              <div class="stats-value">1,234</div>
              <div class="stats-label">今日订单数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="12" :lg="6">
        <el-card class="stats-card">
          <div class="stats-content">
            <div class="stats-icon products">
              <el-icon><Goods /></el-icon>
            </div>
            <div class="stats-info">
              <div class="stats-value">856</div>
              <div class="stats-label">商品总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="12" :lg="6">
        <el-card class="stats-card">
          <div class="stats-content">
            <div class="stats-icon users">
              <el-icon><User /></el-icon>
            </div>
            <div class="stats-info">
              <div class="stats-value">2,456</div>
              <div class="stats-label">活跃用户</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 图表和列表区域 -->
    <el-row :gutter="20" class="charts-row">
      <el-col :xs="24" :lg="12">
        <el-card title="销售趋势">
          <div class="chart-placeholder">
            <el-icon><TrendCharts /></el-icon>
            <p>销售趋势图表</p>
            <p>这里可以集成ECharts等图表库</p>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :lg="12">
        <el-card title="热门商品">
          <el-table :data="hotProducts" style="width: 100%">
            <el-table-column prop="name" label="商品名称" />
            <el-table-column prop="sales" label="销量" width="80" />
            <el-table-column prop="price" label="价格" width="80">
              <template #default="scope">
                ¥{{ scope.row.price }}
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>

    <!-- 最近活动 -->
    <el-card title="最近活动" class="activity-card">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in recentActivities"
          :key="index"
          :timestamp="activity.time"
          :type="activity.type"
        >
          {{ activity.content }}
        </el-timeline-item>
      </el-timeline>
    </el-card>
  </div>
</template>

<script>
import { ref } from 'vue'

/**
 * Vue子应用首页组件
 * @description 展示Vue子应用的主要功能和数据统计
 */
export default {
  name: 'Home',
  setup() {
    // 热门商品数据
    const hotProducts = ref([
      { name: 'iPhone 15 Pro', sales: 156, price: 8999 },
      { name: 'MacBook Air', sales: 89, price: 7999 },
      { name: 'AirPods Pro', sales: 234, price: 1999 },
      { name: 'iPad Air', sales: 67, price: 4399 }
    ])

    // 最近活动数据
    const recentActivities = ref([
      { content: '新订单 #12345 已创建', time: '2023-12-01 14:30', type: 'primary' },
      { content: '商品 "iPhone 15 Pro" 库存不足', time: '2023-12-01 13:15', type: 'warning' },
      { content: '用户 "张三" 完成了订单 #12344', time: '2023-12-01 12:45', type: 'success' },
      { content: '系统维护完成', time: '2023-12-01 10:00', type: 'info' }
    ])

    return {
      hotProducts,
      recentActivities
    }
  }
}
</script>

<style scoped>
/* 首页样式 */
.home {
  max-width: 1200px;
  margin: 0 auto;
}

/* 欢迎卡片样式 */
.welcome-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  margin: 0;
  color: #303133;
}

.welcome-content {
  line-height: 1.6;
}

.welcome-content ul {
  margin: 15px 0;
  padding-left: 20px;
}

.welcome-content li {
  margin: 8px 0;
}

/* 统计卡片样式 */
.stats-row {
  margin-bottom: 20px;
}

.stats-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stats-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.stats-content {
  display: flex;
  align-items: center;
}

.stats-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 24px;
  color: white;
}

.stats-icon.sales {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stats-icon.orders {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stats-icon.products {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stats-icon.users {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.stats-info {
  flex: 1;
}

.stats-value {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 4px;
}

.stats-label {
  font-size: 14px;
  color: #909399;
}

/* 图表区域样式 */
.charts-row {
  margin-bottom: 20px;
}

.chart-placeholder {
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #909399;
  font-size: 16px;
}

.chart-placeholder .el-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

/* 活动卡片样式 */
.activity-card {
  margin-bottom: 20px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .stats-content {
    flex-direction: column;
    text-align: center;
  }
  
  .stats-icon {
    margin-right: 0;
    margin-bottom: 12px;
  }
}
</style> 